package com.tarena.lbs.basic.web.exception;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice("com.tarena.lbs.basic.web.controller")
public class BasicGlobalExceptionHandler {

    @ExceptionHandler(Throwable.class)
    public Result handleThrowable(Throwable e){
        //固定返回一直值
        log.error("系统异常", e);
        return Result.fail();
    }

    @ExceptionHandler(BusinessException.class)
    public Result handleBusinessException(BusinessException exception){
        log.error("业务异常 exception:",exception);
        return Result.fail(exception);
    }
}
